package com.rh.controller;


import com.rh.entity.subject.OneSubject;
import com.rh.service.EduSubjectService;
import com.rh.result.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "课程导入导出与树形结构")
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;
    /**
     * 1.添加课程分类，读取上传文件的内容
     */
    @ApiOperation(value = "1.添加课程分类(导入)")
    @PostMapping("addSubject")
    public ResultVo addSubject(MultipartFile file){
        //得到上传文件MultipartFile,这里传一个eduSubjectService为了方便监听器操作
        subjectService.saveSubject(file,subjectService);
        return ResultVo.ok();
    }
    /**
     * 2.课程分类列表(树形)
     */
    @ApiOperation(value = "2.课程分类列表(树形)")
    @GetMapping("getAllSubject")
    public ResultVo getAllSubject(){
        List<OneSubject> list=subjectService.getAllOneTwoSubject();
        return ResultVo.ok().data("list",list);
    }
    /**
     * 3.导出课程分类
     */
    @ApiOperation(value = "3.导出课程数据")
    @GetMapping("exportSubject")
    public void exportSubject(HttpServletResponse response){
        subjectService.exportSubject(response);
    }
}

